/*
 * Generated file. 
 * 
 * MobileSearch.java
 */
package xsp;

import com.ibm.xsp.page.compiled.AbstractCompiledPage;
import com.ibm.xsp.page.compiled.AbstractCompiledPageDispatcher;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import com.ibm.xsp.page.compiled.NoSuchComponentException;
import com.ibm.xsp.page.compiled.PageExpressionEvaluator;
import java.lang.String;
import com.ibm.xsp.component.UIViewRootEx2;
import com.ibm.xsp.component.xp.XspDiv;
import com.ibm.xsp.component.xp.XspInputText;
import java.lang.Object;
import javax.faces.el.ValueBinding;
import com.ibm.xsp.complex.Attr;
import com.ibm.xsp.extlib.component.mobile.UIToolBarButton;
import com.ibm.xsp.component.xp.XspEventHandler;
import com.ibm.xsp.actions.ExecuteScriptAction;
import javax.faces.el.MethodBinding;

@SuppressWarnings("all")
public class MobileSearch extends AbstractCompiledPageDispatcher{

    private static final String[][] s_libraryVersions = new String[][]{
        {"com.ibm.xsp.extlib.library", "8.5.32006"},  // version of "xe:toolBarButton"
    };
    
    public MobileSearch() {
        super("8.5.3"); // version of xp:inputText attrs
    }

    protected String[][] getLibraryTagVersions() {
        return s_libraryVersions;
    }

    protected AbstractCompiledPage createPage(int pageIndex) {
        return new MobileSearchPage();
    }
    
    protected boolean isCustomControl() {
        return true;
    }

    public static class MobileSearchPage extends AbstractCompiledPage {
        
        private static final ComponentInfo[] s_infos = new ComponentInfo[]{
            ComponentInfo.EMPTY_NORMAL, // 0 "inputtext1"
            ComponentInfo.EMPTY_NORMAL, // 1 eventHandler
            new ComponentInfo(false, new int[]{1}), // 2 "searchbutton"
            new ComponentInfo(false, new int[]{0, 2}), // 3 div
            new ComponentInfo(false, new int[]{3}), // 4 view
        };
        
        public MobileSearchPage() {
            super(4, s_infos );
        }
        
        public int getComponentForId(String id) throws NoSuchComponentException { 
            if( "inputtext1".equals(id) )
                return 0;
            if( "searchbutton".equals(id) )
                return 2;
            return -1;
        }
        
        public UIComponent createComponent(int id, FacesContext context,
                UIComponent parent, PageExpressionEvaluator evaluator)
                throws NoSuchComponentException { 
            switch (id) {
            case 4:
                return createView(context, parent, evaluator);
            case 3:
                return createDiv(context, parent, evaluator);
            case 0:
                return createInputtext1(context, parent, evaluator);
            case 2:
                return createSearchbutton(context, parent, evaluator);
            case 1:
                return createEventHandler(context, parent, evaluator);
            }
            throw new NoSuchComponentException(id);
        }
        
        private UIComponent createView(FacesContext context, 
                UIComponent parent, PageExpressionEvaluator evaluator) {
            UIViewRootEx2 result = new UIViewRootEx2();
            initViewRoot(result);
            return result;
        }

        private UIComponent createDiv(FacesContext context, 
                UIComponent parent, PageExpressionEvaluator evaluator) {
            XspDiv result = new XspDiv();
            result.setStyleClass("mblSearchBar");
            return result;
        }

        private UIComponent createInputtext1(FacesContext context, 
                UIComponent parent, PageExpressionEvaluator evaluator) {
            XspInputText result = new XspInputText();
            String sourceId = "inputText1/@value";
            String valueExpr = "#{requestScope.searchQuery}";
            ValueBinding value = evaluator.createValueBinding(result, valueExpr, sourceId,Object.class);
            result.setValueBinding("value", value);
            Attr attrs2 = new Attr();
            attrs2.setComponent(result);
            attrs2.setValue("Search...");
            attrs2.setName("placeholder");
            result.addAttr(attrs2);
            result.setAutocomplete("off");
            setId(result, "inputText1");
            return result;
        }

        private UIComponent createSearchbutton(FacesContext context, 
                UIComponent parent, PageExpressionEvaluator evaluator) {
            UIToolBarButton result = new UIToolBarButton();
            result.setStyle("position: absolute; right: 9px;");
            result.setLabel("");
            result.setIcon("iconSearch16.png");
            setId(result, "searchButton");
            result.setIconPos("-7,-7,29,29");
            return result;
        }

        private UIComponent createEventHandler(FacesContext context, 
                UIComponent parent, PageExpressionEvaluator evaluator) {
            XspEventHandler result = new XspEventHandler();
            ExecuteScriptAction action = new ExecuteScriptAction();
            action.setComponent(result);
            String sourceId = "searchButton/xp:eventHandler[1]/xp:this.action[1]/xp:executeScript[1]/xp:this.script[1]/text()";
            MethodBinding script = evaluator.createMethodBinding(result,
                    "#{javascript:\n\t\t\t\t\t\t\t\tvar search = getComponent(\'inputText1\').getValue();\n\t\t\t\t\t\t\t\trequestScope.searchQuery = search;\n\t\t\t\t\t\t\t}",
                    null,null, sourceId);
            action.setScript(script);
            action.setSourceReferenceId("searchButton/xp:eventHandler[1]/xp:this.action[1]/xp:executeScript[1]");
            result.setAction(action);
            String sourceId2 = "searchButton/xp:eventHandler[1]/@refreshId";
            String refreshIdExpr = "#{compositeData.dataView}";
            ValueBinding refreshId = evaluator.createValueBinding(result, refreshIdExpr, sourceId2,String.class);
            result.setValueBinding("refreshId", refreshId);
            result.setSubmit(true);
            result.setEvent("onclick");
            result.setRefreshMode("partial");
            return result;
        }

    }
}
